package IO.File;

import java.io.*;

public class DeepCopyUtil {

    public static <T> T DeepCopy(T t) throws IOException, ClassNotFoundException {

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();//字节数组输出流
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
        objectOutputStream.writeObject(t);
        byte[] bytes = outputStream.toByteArray();

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        Object o = objectInputStream.readObject();
        objectInputStream.close();
        objectOutputStream.close();
        outputStream.close();
        byteArrayInputStream.close();

        return  (T)o;
    }


}
